package com.example.web.controller;

import com.example.entity.Organization;
import com.example.service.IOrganizationService;
import com.example.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/companies")
public class OrganizationController {

    @Autowired
    private IOrganizationService organizationService;

    @GetMapping()
    public JsonResult< List<Organization>> getAllHotCompanies(){
        List<Organization> organizationList = organizationService.getAllHotCompanies();
        return JsonResult.success(organizationList);
    }

    @PostMapping()
    public JsonResult insert(@RequestBody Organization organization){
        organizationService.insert(organization);
        return JsonResult.success();
    }

    @GetMapping("/{comId}")
    public JsonResult<Organization> getCompanyByComId(@PathVariable("comId") Long comId){
        Organization organization = organizationService.getById(comId);
        return JsonResult.success(organization);
    }

    @PutMapping("/{comId}")
    public JsonResult updateCompanyByComId(@PathVariable("comId") Long comId,@RequestBody Organization organization){
        organizationService.updateCompanyByComId(comId,organization);
        return JsonResult.success();
    }

    @DeleteMapping("/{comId}")
    public JsonResult deleteCompanyByComId(@PathVariable("comId") Long comId){
        organizationService.deleteCompanyByComId(comId);
        return JsonResult.success();
    }
}
